package com.ternnetwork.core.configuration.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ternnetwork.commons.model.http.BaseResponse;
import com.ternnetwork.commons.utils.JsonUtils;
import com.ternnetwork.core.configuration.dto.IdGeneratorQueryDto;
import com.ternnetwork.core.configuration.entity.IdGenerator;
import com.ternnetwork.core.configuration.service.IdGeneratorService;

@Controller
@RequestMapping("/configuration/idgenerator/*")
public class IdGeneratorController {
	
		@Autowired
		private IdGeneratorService idGeneratorService;
		
		
		 @RequestMapping("/getOne")
	     public @ResponseBody BaseResponse getOne(Long id) {
	     	 return idGeneratorService.getOne(id);
	     }
		
		 @RequestMapping("/add")
	     public @ResponseBody BaseResponse add(String requestJson) throws Exception{
	
			BaseResponse baseResponse = new BaseResponse();
			IdGenerator t = JsonUtils.jsonToObjectThrowsException(requestJson, IdGenerator.class);
			baseResponse = idGeneratorService.add(t);
			return baseResponse;
			 
	     }
	    
		 @RequestMapping("/update")
	     public @ResponseBody BaseResponse update(String requestJson) throws Exception{
	       	 BaseResponse baseResponse=new BaseResponse();
	    	 IdGenerator t=JsonUtils.jsonToObjectThrowsException(requestJson, IdGenerator.class);
			 baseResponse=idGeneratorService.update(t);
			 return baseResponse;
	     }
		
		 @RequestMapping("/findByPage")
	     public @ResponseBody BaseResponse findByPage(@PageableDefault Pageable pageable,IdGeneratorQueryDto dto) {
	      	 return idGeneratorService.findByPage(pageable, dto);
	     }
	    
		 @RequestMapping("/findAll")
	     public @ResponseBody BaseResponse findAll(IdGeneratorQueryDto dto) {
	    	 return idGeneratorService.findAll(dto);
	     }
		
		 @RequestMapping("/deleteById")
	     public @ResponseBody BaseResponse deleteById(Long id) {
	    	 return idGeneratorService.deleteById(id);
	     }
		
		

}
